<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
 <!-- 1. 导入CSS的全局样式 -->
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <!-- 2. jQuery导入，建议使用1.9以上的版本 -->
    <script src="js/jquery-3.2.1.min.js"></script>
    <!-- 3. 导入bootstrap的js文件 -->
    <script src="js/bootstrap.min.js"></script>
    <script type="text/javascript">
    function deleteUser(id){
    	//用户删除安全提示
    	if(confirm("你确定删除吗？")){
    		//访问路径
    		location.href="${ pageContext.request.contextPath}/deluserServlet?id="+id;
    	}
    }

  //对点击删除的id反馈，提交从from表单出来的id去给servlet
    window.onload = function(){
    	 document.getElementById("delSelected").onclick = function(){
    		if(confirm("你确定要删除你所选择的对象吗？")){
    			var flag=false;
    			//判断是否选中条目
    			var cbs = document.getElementsByName("uid");
    			for (var i = 0; i < cbs.length; i++) {
    				if(cbs[i].checked){
    					//有一个条目选中
    					flag=true;
    					break;
    				}
    			}
    			if(flag){
    				document.getElementById("form").submit();
    			}
    		}
    	}
    	 	 //1.获取第一个cb，判断第一个框框的状态，全选和全不选
    	    document.getElementById("firstCb").onclick = function(){
    	        //2.获取下边列表中所有的cb
    	        var cbs = document.getElementsByName("uid");
    	        //3.遍历
    	        for (var i = 0; i < cbs.length; i++) {
    	        //4.设置这些cbs[i]的checked状态 = firstCb.checked
    	            cbs[i].checked = this.checked;
    	        }
    	    }
    }
    
    </script>
</head>
<body>
<div class="container">
    <h3 style="text-align: center">用户信息列表</h3>
    <div style="folat: right; text-align:right;">
   	  <h3>晚上好：${user.username}</h3>
     </div>

   
    
    <div style="float:right;margin:5px;">
    	<a class="btn btn-primary" href="Register.jsp">添加联系人</a>
    	<a class="btn btn-primary" href="javascript:void(0);" id="delSelected">删除选中</a>
    	
    </div>
  <form id="form" action="${pageContext.request.contextPath}/delUsersServlet" method="post">
    <table border="1" class="table table-bordered table-hover">
            <tr class="success">         
            <th><input type="checkbox" id="firstCb"></th>
            <th>ID</th>
            <th>姓名</th>
            <th>用户名</th>
            <th>性别</th>
            <th>年龄</th>
            <th>籍贯</th>
            <th>QQ</th>
            <th>邮箱</th>
            <th>操作</th>
        </tr>
        <c:forEach items="${pb.list}" var="user" varStatus="s">
            <tr>
            	<td><input type="checkbox" name="uid" value="${user.userid}"></td>
                <td>${user.userid}</td>
                <td>${user.name}</td>
                <td>${user.username}</td>
                <td>${user.gender}</td>
                <td>${user.age}</td>
                <td>${user.address}</td>
                <td>${user.qq}</td>
                <td>${user.email}</td>
                <td><a class="btn btn-default btn-sm" href="${pageContext.request.contextPath}/finduserServlet?id=${user.userid}">修改</a>&nbsp;
                  <a class="btn btn-default btn-sm" href="javascript:deleteUser(${user.userid});">删除</a></td>
            </tr>
        </c:forEach>
    </table>
  </form>
     <div>
        <nav aria-label="Page navigation">
            <ul class="pagination">
                <c:if test="${pb.currentPage == 1}">
                    <li class="disabled">
                      <a href="${pageContext.request.contextPath}/findUserByPageServlet?currentPage=${pb.currentPage}&rows=5" aria-label="Previous">
                        <span aria-hidden="true">&laquo;</span>
                     </a>
              	    </li>
                </c:if>
                <c:if test="${pb.currentPage != 1}">
                    <li>
                   	  <a href="${pageContext.request.contextPath}/findUserByPageServlet?currentPage=${pb.currentPage - 1}&rows=5" aria-label="Previous">
                        <span aria-hidden="true">&laquo;</span>
                      </a>
                    </li>
                </c:if>
                   
                <c:forEach begin="1" end="${pb.totalPage}" var="i" >
				
                    <c:if test="${pb.currentPage == i}">
                        <li class="active"><a href="${pageContext.request.contextPath}/findUserByPageServlet?currentPage=${i}&rows=5">${i}</a></li>
                    </c:if>
                    <c:if test="${pb.currentPage != i}">
                        <li><a href="${pageContext.request.contextPath}/findUserByPageServlet?currentPage=${i}&rows=5">${i}</a></li>
                    </c:if>
                </c:forEach>
                
				<c:if test="${pb.currentPage==pb.totalPage}">
                    <li class="disabled">
                      <a href="${pageContext.request.contextPath}/findUserByPageServlet?currentPage=${pb.currentPage}&rows=5" aria-label="Next">
                        <span aria-hidden="true">&raquo;</span>
                     </a>
              	  </li>
                </c:if>
                <c:if test="${pb.currentPage!=pb.totalPage}">
                    <li>
                   	  <a href="${pageContext.request.contextPath}/findUserByPageServlet?currentPage=${pb.currentPage + 1}&rows=5" aria-label="Next">
                   	     <span aria-hidden="true">&raquo;</span>
                	  </a>
              	    </li>
                </c:if>
                <span style="font-size: 25px;margin-left: 5px;">
                                                 共${pb.totalCount}条记录，共${pb.totalPage}页
                </span>
            </ul>
        </nav>
    </div>
</div>
</body>
</html>